<?php $burl = $this->baseUrl();?>                              
<?php if (isset($this->paginator) && count($this->paginator)):?>
<?php if (!$this->isAjax):?> 
<div class="tabs" style="margin-bottom: 10px;">
<ul class="navigation" id="poll_filter_privacy"></ul>    
</div>
<div id="question_browse_container">
<?php endif;?>
    <?php foreach ($this->paginator as $question): ?>
        <div class="poll_title">
            <?php $owner = Engine_Api::_()->user()->getUser($question->user_id);?>
            <div class="owner_avatar"><?php echo $this->htmlLink($owner->getHref(), $this->UPhoto($owner, 'thumb.icon'));?></div>
            <div class="questions_question_content">
                <?php echo $this->translate('%s asked %s', $this->htmlLink($owner->getHref(), $owner->getTitle()), $this->htmlLink($question->getHref(), $question->getTitle()));?>
                <div class="poll_options_container">
                <?php echo $this->partial('_displayPoll.tpl', 'poll', array('item' => $question, 'options' => $question->getOptions(), 'show_title' => true));?>
                </div>
            </div>
        </div>        
    <?php endforeach; ?>
<?php if (!$this->isAjax):?> 
</div>
<?php endif;?>    
    <?php
    $tc = $this->paginator->getTotalItemCount();
    $ipp = $this->paginator->getItemCountPerPage();
    $ci = $this->paginator->getCurrentItemCount();
    $cp = $this->paginator->getCurrentPageNumber();
    ?> 
    <?php if ((($cp - 1) * $ipp) + $ci < $tc):?>    
        <?php if (!$this->isAjax):?>
        <div id="question_bar_show_more">
        <a id="show_more" class="show_more" onclick="iShowMoreQuestions($(this))">
            <span class="show_more_text"><?php echo $this->translate('See more');?></span>
        </a>
        </div>
        <?php else:?> 
        <script type="text/javascript">
        iBrowseCurrentPage = <?php echo $cp;?>;
        if (!$('show_more')) {
            $a = new Element('a', {
                id : 'show_more',
                class : 'show_more',
                html : '<span class="show_more_text"><?php echo $this->translate('See more');?></span>',
                events : {
                    click : function(e) {
                        e.stop();
                        iShowMoreQuestions($(this))
                    }
                }
            }).inject($('question_bar_show_more'));
        }
        </script>        
        <?php endif;?>
    <?php else: ?>
    <script type="text/javascript">if ($('show_more')) $('show_more').destroy();</script>
    <?php endif;?>

<?php if (!$this->isAjax):?>    
    <script type="text/javascript">
    var iBrowseCurrentPage = <?php echo $cp;?>;
    var iQuestionPrivacy = '<?php echo $this->privacy;?>';
    function iShowMoreQuestions($a) {
        $a.getChildren().getLast().set('html', '<i class="question_more_loading"></i>');
        $request = new Request.HTML({
            url : '<?php echo $this->url(array('module' => 'core', 'controller' => 'widget', 'action' => 'index', 'content_id' => $this->identity), 'default', true) ?>',
            format : 'html',
            data : {
                privacy : iQuestionPrivacy,                
                page : (iBrowseCurrentPage + 1),
                search : '<?php echo $this->search;?>',
                order : '<?php echo $this->order;?>',
                isAjax : 1
            },
            evalScripts : true,
            onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
                if (responseHTML) {
                    $('question_browse_container').set('html', $('question_browse_container').get('html') + responseHTML);
                }    
                setTimeout(responseJavaScript, 1000);
                $a.getChildren().getLast().set('html', '<?php echo $this->translate('See more');?>');
            }
        }).post();
    }
    var changeQuestionPrivacy = function($privacy) {
        iQuestionPrivacy = $privacy;
        $request = new Request.HTML({
            url : '<?php echo $this->url(array('module' => 'core', 'controller' => 'widget', 'action' => 'index', 'content_id' => $this->identity), 'default', true) ?>',
            format : 'html',
            data : {
                privacy : iQuestionPrivacy,             
                isAjax : 1
            },
            evalScripts : true,
            onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
                if (responseHTML) {
                    $('question_browse_container').set('html', responseHTML);
                }    
                setTimeout(responseJavaScript, 1000); 
            }
        }).post();    
    }
    <?php if ($this->viewer->getIdentity()):?>
    window.addEvent('domready', function(){
        $ul = $('poll_filter_privacy');
        $li = new Element('li', {
            html : '<a href="javascript:void(0)"><?php echo $this->translate('All Questions');?></a>',
            class : 'active',
            events : {
                click : function(e) {
                    e.stop();
                    changeQuestionPrivacy('all');
                    $ul.getChildren('li').removeClass('active');
                    $(this).addClass('active');
                }
            }
        }).inject($ul);
        $li = new Element('li', {
            html : '<a href="javascript:void(0)"><?php echo $this->translate('Friends Questions');?></a>',
            events : {
                click : function(e) {
                    e.stop();
                    changeQuestionPrivacy('friends');
                    $ul.getChildren('li').removeClass('active');
                    $(this).addClass('active');
                }
            }
        }).inject($ul);
        $li = new Element('li', {
            html : '<a href="javascript:void(0)"><?php echo $this->translate('Public Questions');?></a>',
            events : {
                click : function(e) {
                    e.stop();
                    changeQuestionPrivacy('public');
                    $ul.getChildren('li').removeClass('active');
                    $(this).addClass('active');
                }
            }
        }).inject($ul);    
    });
    <?php endif; ?>
    </script>
<?php endif;?>      
<?php else: ?>
<div class="tip">
  <span>
    <?php echo $this->translate("Nothing has been posted here yet!") ?>
  </span>
</div>
<script type="text/javascript">if ($('show_more')) $('show_more').destroy();</script>    
<?php endif;?>